<template>
    <div class="app">
        <div>
        <div class="top-banner">
            <img :src="navbar">
        </div> 
        <div class="title-line">
          <span class="tit" style="font-size: 38px;">管理员登录</span>
        </div>
        </div>
        <!-- 用户注册表单 -->
        <el-form ref="form" :model="form" label-width="80px" class="loginForm">
            <el-form-item
            prop="userid"
            :rules="[
                  { required: true, message: '请输入用户ID', trigger: 'blur' },
                  { pattern: /\d|\w|\W/, message: '请输入正确的用户ID', trigger: 'blur' }
                    ]"
            >
              <el-input v-model="form.userid" placeholder="您的用户ID"></el-input>
            </el-form-item>
            <el-form-item 
            prop="password"
            :rules="[
                  { required: true, message: '请输入密码', trigger: 'blur' },
                  { pattern: /\d|\w/, message: '请输入正确的密码', trigger: 'blur' }
                    ]"
            >
              <el-input v-model="form.password" type="password" placeholder="您的密码"></el-input>
            </el-form-item>
            <el-form-item>
            <center>
             <el-button type="primary" @click="submitForm('form')" style="width:152px">登录</el-button>
             <el-button  style="width:152px;" @click="register">注册
             </el-button>
            </center>
             </el-form-item>
        </el-form>
    </div>
</template>

<script>
import {apiurl} from "../../service/api.js";
import background from '../../assets/navbar1.png'

export default {
    name : 'login',
    created() {     
        //查看是否保存本地信息
        var remember = JSON.parse(localStorage.getItem("remember"))
        if (remember!=null){
            this.form.username = remember.username
            this.form.password = remember.password
        }
    },
    data(){
        return{
            navbar : background,

            form:{
                userid: '',
                password: '',
            },
        }

    },methods:{
        submitForm(formName){
          this.$refs[formName].validate((valid) => {
            if (valid) {  //用户信息不能为空
              var that = this
              var logindata = {
                Uuid : that.form.userid,
                Password : this.$md5(that.form.password),
              }
            that.$axios.post({
              url: apiurl.adminlogin,
              data:logindata,
              type: 'application/json;charset=UTF-8'
            }).then(res => {  
              if(res.data.code==200){  //登录成功
                  that.$message.success(`登录成功`)
                  that.$router.push('/admin/manage')
              }else{
                that.$message.error(res.data.msg)
              }
            })
            }else {
                return false
              }
          })
        },register(){
           this.$router.push('/admin/register')
        }
    }
}
</script>

<style scpoed> /*css局部生效*/
    .navbar{
      top: 0;
    }

    *{
    padding: 0;
    margin: 0;
    font-family: PingFangSC-Medium;
    -webkit-tap-highlight-color: rgba(255,255,255,0);
    }
    .bili-header-m {
    font: 12px 'Helvetica Neue', Helvetica, Arial, 'Microsoft Yahei', 'Hiragino Sans GB', 'Heiti SC', 'WenQuanYi Micro Hei', sans-serif;
    position: relative;
    z-index: 10000;
    background: #fff;
    margin: 0;
    padding: 0;
    }
    .top-banner {
    background: #00a0d8;
    height: 86px;
    text-align: center;
    margin-bottom: 20px;
    }
    a, img {
    border: none;
    }
    .title-line {
    width: 980px;
    height: 28px;
    margin: 0 auto;
    border-bottom: 1px solid #ddd;
    margin-bottom: 28px;
    text-align: center;
    }
    .title-line .tit {
    height: 56px;
    line-height: 56px;
    margin: 0 auto;
    padding: 0 20px;
    background: #fff;
    text-align: center;
    }
    .loginForm {
    width: 400px;
    margin: 0 auto;
    padding: 60px 0;
    }
    
    .identifyCaptcha {
    position: relative;
    top: 10px;
    width: 140px;
    height: 30px;
    border-radius: 2px;
    border: none;
    }
    
    .remember {
    margin: 10px 0;
    color: #717171;
    width: 410px;
    font-size: 12px;
    }
   
    .remember span {
    color: #bbb;
    margin-left: 10px;
    }



</style>